#ifndef GAME_H
#define GAME_H

#include "Scene.h"
#include "SceneMain.h"
#include <SDL.h>
#include <SDL_mixer.h>
#include "Object.h"

class Game
{
public:
    static Game& getInstance() {
        static Game instance;
        return instance;
    };

    ~Game();
    void run();
    void init();
    void clean();
    void changeScene(Scene* scent);

    void handleEvent(SDL_Event* event);
    void update(float deltaTime);
    void render();

    SDL_Window* getWinow() {return window;}
    SDL_Renderer* getRenderer() {return renderer;}
    int getWindowWidth() {return windowWidth;}
    int getWindowHeight() {return windowHeight;}
    void backgroundUpdate(float deltaTime);
    void renderBackground();
    SDL_Point renderTextCentered(std::string text, float posY, bool isTitle);
    void renderTextPos(std::string text, int posX, int posY, bool isLeft);
    void setFinalScore(int score) { finalScore = score;}
    int getFinalScore() { return finalScore;}
    void insertLeadBoard(int score, std::string name);
    std::multimap<int, std::string, std::greater<int>>& getLeaderBoard() {return leaderBoard;}
    

private:
    Game();
    // 删除拷贝与赋值构造函数
    Game(const Game&) = delete;
    Game& operator=(const Game&) = delete;
    bool isFullscreen = false;
    std::multimap<int, std::string, std::greater<int>> leaderBoard; // 使用 multimap 来存储分数和名字，分数作为键， 名字作为值

    bool isRuning = true;
    Scene* currentScene = nullptr;
    SDL_Window* window = nullptr;
    SDL_Renderer* renderer = nullptr;
    int windowWidth = 600;
    int windowHeight = 800;
    int FPS = 60;
    Uint32 frameTime;
    float deltaTime;
    Background nearStars;
    Background farStars;

    TTF_Font* titleFont;
    TTF_Font* textFont;
    Scene* currentScent = nullptr;
    int finalScore = 0;
    void saveData();
    void loadData();
};

#endif
